import defineReactiveData from "./reactive";

import {arrMethods} from "./array";
import observeArr from "./observeArr";

function Observer(data){
    // debugger
    if(Array.isArray(data)){
        data.__proto__ = arrMethods
        // console.log(data)

        // 递归 数组的数组
        observeArr(data)

    }else{
        this.walk(data)
    }
}

Observer.prototype.walk = function (data){
    let keys = Object.keys(data)
    // console.log('keys ==== ', keys)
    // debugger
    for(let i = 0;i<keys.length; i++){
        let key = keys[i]
        let value = data[key]
        // console.log('递归walk', value)
        defineReactiveData(data, key, value)
    }

}

// {} defineProperty
// [] 自己去写

export default Observer